/**
 * 添加或者修改页面
 */
var StorageStockInfoDlg = {
    data: {
        operateId: "",
        operateName: "",
        customerId: "",
        customerName: "",
        warehouseId: "",
        warehouseName: "",
        areaId: "",
        areaNumber: "",
        positionId: "",
        positionNumber: "",
        trayId: "",
        trayNumber: "",
        goodsId: "",
        goodsName: "",
        goodsNumber: "",
        num: "",
        balenum: "",
        canNum: "",
        stockWeight: "",
        stockVolume: "",
        unitprice: "",
        stockMoney: "",
        deliverId: "",
        deptId: "",
        version: "",
        createTime: "",
        updateTime: "",
        createUser: "",
        updateUser: ""
    }
};
/**
 * 详情对话框
 */
var StoragePutSingleInfoDlg = {
    data: {
    	positionNumber: "",
		positionId:""
    }
};
layui.use(['form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //查询库区
    form.on('select(warehouseId)',function(){
        $("#areaId").empty();
        $.ajax({
            url:Feng.ctxPath + '/basicArea/Querylist',
            dataType:"json",   //返回格式为json
            async: false,
            data:{"areaWarehouseId":$("#warehouseId").val()},    //参数值
            type:"post",   //请求方式
            success:function(data){
                if(data.length>0){
                    var str = "<option value=''>请选择</option>";
                    $.each(data,function(key,value){
                        str += "<option value='"+value.id+"'>"+value.areaNumber+"</option>";
                    });
                    $("#areaId").html(str);
                }
            }
        });
        form.render('select');
    });

    //点击选择库位
    $('#selectposition').click(function () {
        layer.open({
            type: 2,
            title: '选择库位',
            area: ['700px', '400px'],
            content: Feng.ctxPath + '/storageStock/toPositionStock?positionAreaId='+$("#areaId").val()+'&warehouseId='+$("#warehouseId").val(),
            end: function () {
                $("#positionNumber").val(StoragePutSingleInfoDlg.data.positionNumber);//库位编号
            }
        });
    });

    //点击商品名称
    $("#goodsName").click(function(){
        layer.open({
            type: 2,
            title: '选择商品',
            area: ['900px', '600px'],
            content: Feng.ctxPath + '/storageStock/toChoiceGoods?goodsCustomerId=' + $("#customerId").val(),
            end: function () {
                $("#goodsId").val(StorageStockInfoDlg.data.goodsId);//商品id
                $("#goodsName").val(StorageStockInfoDlg.data.goodsName);//商品名称
                $("#goodsNumber").val(StorageStockInfoDlg.data.goodsNumber);//商品编号
            }
        });
    });

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/toolStorageStock/addItem", function (data) {
        	if (data.success){
	            Feng.success("添加成功！");
            	window.location.href = Feng.ctxPath + '/toolStorageStock'
        	} else {
            	Feng.error("添加失败！" + data.message)
        	}
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        window.location.href = Feng.ctxPath + '/toolStorageStock'
    });

});